package org.mianshi.zhuanzhuan;



//读excel表文件,发送邮件,保证读取速度的前提下,内存不溢出(10G的excel,2g的内存)


import java.io.*;
        import java.util.*;

public class 文件导入 {

    private static final int BATCH_SIZE = 100; // 每次处理的行数

    public static void main(String[] args) {
        File file = new File("path/to/excel.csv");

        // 存储读取的数据
        List<String> batchData = new ArrayList<>(BATCH_SIZE);

        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = reader.readLine()) != null) {
                batchData.add(line);

                // 一旦达到预定的批量大小，就发送邮件并清空批次
                if (batchData.size() >= BATCH_SIZE) {
                    sendBatchEmails(batchData);
                    batchData.clear();
                }
            }

            // 处理剩余数据（如果有）
            if (!batchData.isEmpty()) {
                sendBatchEmails(batchData);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 模拟发送邮件的方法
    private static void sendBatchEmails(List<String> data) {
        for (String entry : data) {
            // 发送邮件逻辑
            System.out.println("Sending email for: " + entry);
        }
    }
}
